package com.peisong.controller;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.upload.UploadFile;
import com.peisong.core.view.InvokeResult;
import com.peisong.model.Comment;
import com.peisong.model.Employment;
import com.peisong.model.Shoucang;

import java.io.*;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created by 张凤 on 2016/11/10.
 */
public class ReleaseController extends Controller {

    /**
     * 评论列表
     */
    public void commentData() {
        Integer id = this.getParaToInt("id");
        List<Record> data = Employment.dao.commentData(id);
        this.renderJson(data);
    }
    /**
     * 评论
     */
    public void comment() {
        Comment comment = this.getModel(Comment.class, "");
        comment.setAddtime(new Date());
        comment.save();
        this.renderJson(1);
    }


    /**
     * 详情
     */
    public void detail() {
        Integer id = this.getParaToInt("id");
        Employment data = Employment.dao.findById(id);
        Integer clickNum = data.getClickNum();
        data.setClickNum(++clickNum);
        data.update();
        this.renderJson(data);
    }

    /**
     * 加入收藏
     */
    public void addShoucang() {
        Shoucang s = this.getModel(Shoucang.class, "");
        s.setAddtime(new Date());
        s.save();
        this.renderJson(1);
    }
    /**
     * 发布
     */
    public void releaseUpload(){
        Employment emp = this.getModel(Employment.class, "");
        String temp = "/upload/temp/";
        int maxfile = 5 * 1024 * 1024;
        UploadFile uf = getFile("fileName",".."+temp, maxfile, "UTF-8");
        emp.setFile(temp+uf.getFileName());
        emp.save();
        this.renderJson("1");
       }

    public void pageFind(){
        List<Record> list = Employment.dao.pageFind(0,0);
                if (list.size()>0){
                    this.renderJson(list);
                }
    }
}
